﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YuriiOnufreiv
{
    public class StringManipulator
    {
        public static int Add(string numbers)
        {
            if (numbers.Equals(""))
                return 0;
            int result = 0;
            string[] splitedString;
            if (numbers.Contains("//"))
            {
                int delimiterStartIndex = numbers.IndexOf('[') + 1;
                int delimiterEndIndex = numbers.IndexOf(']');
                int delimiterLength = delimiterEndIndex - delimiterStartIndex;
                int numbersStartIndex = numbers.IndexOf('\n') + 1;
                int numbersLength = numbers.Length - numbersStartIndex;
                string delimiter = numbers.Substring(delimiterStartIndex, delimiterLength);
                splitedString = numbers.Substring(numbersStartIndex, numbersLength).Split(new string[] { delimiter }, StringSplitOptions.None);
            }
            else
                splitedString = numbers.Split(new Char[] { ',', '\n' });
            StringBuilder negativeValues = new StringBuilder();
            foreach (string s in splitedString)
            {
                if (s.Trim() != "")
                {
                    int number = Convert.ToInt32(s);
                    if (number < 0)
                        negativeValues.Append(s);
                    else if (number <= 1000)
                        result += number;
                }
            }
            if (negativeValues.Length != 0)
                throw new ArgumentException("negatives not allowed: " + negativeValues.ToString());
            return result;
        }

        static void Main(string[] args)
        {
        }
    }
}
